package com.gxa.service.impl;

import com.gxa.entity.GenarateCode;
import com.gxa.mapper.GenarateCodeMapper;
import com.gxa.service.GenarateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class GenarateCodeServiceImpl implements GenarateCodeService {

    @Autowired
    private GenarateCodeMapper genarateCodeMapper;

    @Override
    public void add(GenarateCode genarateCode) {
        Date dt=new Date();
        String year=String.format("%tY", dt);
        String mon=String .format("%tm", dt);
        String day=String .format("%td", dt);
        String h=String .format("%tH", dt);
        String m=String .format("%tM", dt);
        String s=String .format("%tS", dt);
        String id = year+mon+day+h+m+s;
        System.out.println("id-----------"+id);
        genarateCode.setId(id);
        System.out.println("完整的验证码---------------------"+genarateCode.toString());
        this.genarateCodeMapper.add(genarateCode);
    }

    @Override
    public String queryNewOneCode() {
        String code = this.genarateCodeMapper.queryNewOneCode();
        return code;
    }
}
